/* 
 * File:   Node.h
 * Author: stuart
 *
 * Created on December 9, 2011, 3:29 PM
 */

#ifndef NODE_H
#define	NODE_H

#include "Imagem.h"
#include "Util.h"
#include <vector>
#include <map>

#define GOLDEN_RATIO 0.61803

using namespace std;

enum NodeType { LEAF, BISS_H, BISS_V };
enum SolveType { WIDTH, HEIGHT };

class Node {
private:
    Imagem image;
    Node *left, *right;
    NodeType type;
    double width, height;
    void enumImages(int* i);
    int num;
    void rootEq(map<int, double> *A, double *B, double alpha, double beta, SolveType solveType);
    void treatNode(map<int, double> *A, double *B, double alpha, double beta, NodeType type, bool opposite, SolveType solveType);
    void treatLeaf(map<int, double> *A, double *B, double alpha, double beta, NodeType type, bool opposite, SolveType solveType);
    void treatBiss(map<int, double> *A, double *B, double alpha, double beta, NodeType type, bool opposit, SolveType solveTypee);
    void treatNodes(vector<map<int, double> > *A, vector<double> *B, double alpha, double beta, SolveType solveType);
    void treatSubTree(map<int, double> *A, double *B, double alpha, double beta, SolveType solveType);
//    void applyMetrics(vector<double> widths, double alpha, double beta, Util u);
//    void applyMetrics(vector<double> widths, vector<double> heights);
    void applyWidths(vector<double> widths);
    void applyHeights(vector<double> heights);
    int getNumImages();
public:
    void setNum(int n);
    int getNum();
    Node(vector<Imagem> imagens, double width, double height);
    Node(Node* left, NodeType type, Node* right);
    Node(Imagem imagem);
    void setImage(Imagem image);
    Imagem getImage();
    bool isLeaf();
    NodeType getType();
    Node* getLeft();
    Node* getRight();
    void setLeft(Node* left);
    void setRight(Node* right);
    void setType(NodeType type);
    void setBounds(double width, double height);
    double getWidth();
    double getHeight();
    void normalize(double alpha, double beta, Util u, SolveType solveType);
};

#endif	/* NODE_H */

